package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.SelectNumber;
import com.wenlin.myproduction.util.TypeData;
import com.wenlin.myproduction.util.TypeDataNames;
import com.wenlin.myproduction.util.UI;

import org.greenrobot.eventbus.EventBus;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @author 文琳
 * @Email 377979485@qq.com
 * @desc
 * @time 2023-02-12 星期日 20:31
 */
public class SelectNumberBinder extends ItemViewBinder<SelectNumber, SelectNumberBinder.Holder> {


    @NonNull
    @Override
    protected Holder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new Holder(inflater.inflate(R.layout.item_select_number, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull Holder holder, @NonNull SelectNumber item) {
        UI.setText(holder.tv, item.getNum());
        UI.setOnClickListener(holder.tv, v -> EventBus.getDefault().post(new TypeData<>(TypeDataNames.clickSelectNumber, item)));
        UI.setBackgroundResource(holder.tv, item.isChecked() ? R.drawable.btn_green_rect : 0);
    }

    static class Holder extends RecyclerView.ViewHolder {
        TextView tv;

        public Holder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv);
        }
    }
}
